﻿using System;
using System.Linq;
using System.Text.Json.Serialization;

using Xc.DataAccess.Core;

namespace Xc.Logics.HyperTerminalCore.Udp.ViewModels
{
    /// <summary>
    /// 升级包信息
    /// </summary>
    public class PackageInfo : ViewModelBase
    {
        string version;
        /// <summary>
        /// 版本
        /// </summary>
        public string Version
        {
            get => version;
            set
            {
                if (version == value)
                {
                    return;
                }

                version = value;
                RaisedPropertyChanged();
            }
        }
        ushort packageCheck;
        /// <summary>
        /// CRC校验
        /// </summary>
        public ushort PackageCheck
        {
            get => packageCheck;
            set
            {
                if (packageCheck == value)
                {
                    return;
                }

                packageCheck = value;
                RaisedPropertyChanged();
            }
        }
        ushort packageSize;
        /// <summary>
        /// 分片的大小
        /// </summary>
        public ushort PackageSize
        {
            get => packageSize;
            set
            {
                if (packageSize == value)
                {
                    return;
                }

                packageSize = value;
                RaisedPropertyChanged();
            }
        }
        /// <summary>
        /// 分片总数
        /// </summary>
       [JsonIgnore]
        public ushort PackageCount
        {
            get
            {
                if (PackageInfoItems == null)
                {
                    return 0;
                }
                return (ushort)PackageInfoItems.Length;
            }
        }
        PackageInfoItem[] packageInfoItems;
        /// <summary>
        /// 固件包信息
        /// </summary>
        public PackageInfoItem[] PackageInfoItems
        {
            get => packageInfoItems;
            set
            {
                if (packageInfoItems == value)
                {
                    return;
                }

                packageInfoItems = value;
                RaisedPropertyChanged();
            }
        }

    }
}
